/**
 * Project: TacticaPescaditos
 * File: ChaseBall.java
 */
package org.javahispano.javacup.tacticas_aceptadas.Pescaditos.com.chidotronics.javacup.fsm.state;

import org.javahispano.javacup.tacticas_aceptadas.Pescaditos.com.chidotronics.javacup.TeamPlayer;
import org.javahispano.javacup.tacticas_aceptadas.Pescaditos.com.chidotronics.javacup.messages.Telegram;

/**
 * @author Carlos Alberto
 * class: ChaseBall
 */
public class ChaseBall implements State<TeamPlayer> {
	/**
	 * 
	 */
	
	private String name;
	
	private ChaseBall() {
		this.name = "ChaseBall";
	}

	public static final State<TeamPlayer> instance = new ChaseBall();

	public void enter(TeamPlayer player) {
		player.getSteering().seekOn();
		player.getSteering().setTarget(player.getBall().getPosition());
		execute(player);
		
	}

	public void execute(TeamPlayer player) {

		if (!player.getTactica().isKickGoal()){



			if (player.canKick()){
				player.getStateMachine().changeState(KickBall.instance);	
				return;
			}

			if (player.isClosestToBall()) {
				player.getSteering().setTarget(player.getBall().getPosition());
				return;
			}
		}

		player.getStateMachine().changeState(Wait.instance);		 

	}

	public void exit(TeamPlayer player) {
		player.getSteering().seekOff();
		
	}

	public boolean onMessage(TeamPlayer o, Telegram telegram) {
		return false;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		return this.name.hashCode();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return this.name;
	}

	
}
